<!--
 * @Author: wangding
 * @Date: 2020-11-06 11:29:36
 * @LastEditTime: 2020-11-06 12:20:43
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\overview-inverter\batteryViews\edition.vue
-->
<template>
    <div class="edition-main-box" >
        <div class="head1-box">
            <div class="name">{{$t('batteryAnalysis.MasterVerSn')}}</div>
            <div class="centert" >{{dataList.masterSN || ''}}</div>
        </div>
        <div class="head1-box">
            <div class="name">{{$t('batteryAnalysis.mainVersionNumber')}}</div>
            <div class="centert">{{dataList.batteryMasterVer}}</div>
        </div>
        <div>
            <baseTable  row-key='sid' :data="dataRows" border  stripe   :column='column' :select='false'>
                <template #index="{data}">
                    {{$t('batteryAnalysis.SlaVer')+data.index}}
                </template>
            </baseTable>
        </div>
    </div>
</template>

<script>
import baseTable from '../../../components/common/baseTable'
export default {
    components: {
        baseTable
    },
    props: {

    },
    data() {
        return {
            dataRows:[],
            dataList:{
                masterSN:'',
                batteryMasterVer:""
            },
            column:[{
                title: this.$t('batteryAnalysis.serialNumber'),
                value: 'index',
                slot: 'index'
            },{
                title: this.$t('batteryAnalysis.SlaVerSn'),
                value: 'sn',
                slot: 'sn'
            },{
                title: this.$t('batteryAnalysis.type'),
                value: 'code',
                slot: 'code'
            },{
                title: this.$t('batteryAnalysis.edition'),
                value: 'num',
                slot: 'num'
            }],
            batSlaverType:[]
        };
    },
    computed: {

    },
    watch: {

    },
    created() {

    },
    mounted() {
        this.getDictionaryBatch()
    },
    methods: {
        async deviceGetInverterFromRedis(){
            let res = await this.API.deviceGetInverterFromRedis({
                inverterSN:sessionStorage.getItem('selRow_inverter_sn')
            })
            this.dataList = res
            let data = res
            let arr = []
            for(let i=1;i<=data.batterySlaveNum/2;i++){
                let  bst = 2*i-1;
                let code = ''
                let  brandNumber = parseInt(data.batteryBrand)*10;
                for(let j=0;j<this.batSlaverType.length;j++){
                    let typeValue = brandNumber + parseInt(data["batterySlaveType"+bst]);
                    if(typeValue==parseInt(this.batSlaverType[j].value)){
                        code = this.batSlaverType[j].code;
                        break;
                    }
                }
                let obj ={
                    index:i,
                    sn:data["slave"+bst+"_"+(bst+1)+"SN"],
                    code:code,
                    num:data["batterySlaveVer"+bst]
                }
                arr.push(obj)
            }
            this.dataRows = arr
        },
        async getDictionaryBatch(){
            let res = await this.API.getDictionaryBatch({
                dictCodes:'BATTERY_SLAVE_TYPE_NEW',
                lang:localStorage.getItem('lan') || 'zh_CN'
            })
            this.batSlaverType = res.BATTERY_SLAVE_TYPE_NEW || []
            this.deviceGetInverterFromRedis()
        },
    },
};
</script>

<style  lang="less" scoped>
.edition-main-box{
    .head1-box{
        width: 100%;
        height: 23px;
        background-color: #666;
        display: flex;
        .name{
            flex: 1;
            text-align: center;
            line-height: 23px;
            font-size: 14px;
            color: #fff;
        }
        .centert{
            flex: 3;
            text-align: center;
            line-height: 23px;
            font-size: 14px;
            color: #fff;
        }
    }
}
</style>
